import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBWorkTaiBaseYiJiModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBWorkTaiGongGongYouXuanModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBZhuanShuYingYongPage/YBMiShuProvider/YBShuaXinShengYuChiShuEventBus.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBWorkTaiNetWork/YBBaseWorkTaiNetWorkManager.dart';

//公共商机
class YBYiJiTongLvSiTongProvider with ChangeNotifier{
  List<YBWorkTaiBaseYiJiModel> _yijiList = List<YBWorkTaiBaseYiJiModel>();

  List<YBWorkTaiBaseYiJiModel> get yiJiModelList => _yijiList;

  RefreshController _easyRefreshController = RefreshController();

  RefreshController get easyRefreshController => _easyRefreshController;

  int _currentPage = 1;

  Future refreshData(String sysCode) async {
    _currentPage = 1;
    getYiJiDataList(_currentPage, sysCode);
  }

  Future loadData(String sysCode) async {
    _currentPage++;
    getYiJiDataList(_currentPage, sysCode);
  }

  Future getYiJiDataList(int page,String sysCode) async {
    YBBaseWorkTaiNetWork.workTaiYiJitongLvSitong({
      "sysCode":sysCode,
      "pageSize":20,
      "pageNo":page,
    },success:(data){
      print("----$data----");
      _easyRefreshController.loadComplete();
      _easyRefreshController.refreshCompleted();
      int totalPage = data['totalPage'];
      if (totalPage == page) {
        _easyRefreshController.loadNoData();
      }
      List resultList = data['result'];
      if (!ObjectUtil.isEmptyList(resultList)) {
        _yijiList.addAll(resultList.map((e){
          return YBWorkTaiBaseYiJiModel.fromJson(e);
        }).toList());
        print('--蚁集&律司-$_yijiList--');
        notifyListeners();
      }
    },fail: (error){
      _easyRefreshController.refreshCompleted();
    });
  }
}

//优选商机
class YBYiJiLvSiBaseYouXuanShangJi with ChangeNotifier {

  List<YBWorkTaiBaseYiJiModel> _youXuanList = List<YBWorkTaiBaseYiJiModel>();

  List<YBWorkTaiBaseYiJiModel> get youXuanModelList => _youXuanList;

  RefreshController _easyRefreshController = RefreshController();

  RefreshController get easyRefreshController => _easyRefreshController;

  int _currentPage = 1;

  Future refreshData(String sysCode,String sourceType) async {
    _currentPage = 1;
    getYouXuanDataList(_currentPage, sysCode,sourceType);
  }

  Future loadData(String sysCode, String sourceType) async {
    _currentPage++;
    getYouXuanDataList(_currentPage, sysCode,sourceType);
  }

  Future getYouXuanDataList(int page,String sysCode,String sourceType) async {
    YBBaseWorkTaiNetWork.workTaiYiJitongLvSitongYouXuanList({
      "sysCode":sysCode,
      "sourceType":sourceType,
      "pageSize":20,
      "pageNo":page,
    },success:(data){
      print("----$data----");
      _easyRefreshController.refreshCompleted();
      _easyRefreshController.loadComplete();
      int totalPage = data['totalPage'];
      if (totalPage == page) {
        _easyRefreshController.loadNoData();
      }
      List resultList = data['result'];
      if (!ObjectUtil.isEmptyList(resultList)) {
        _youXuanList.addAll(resultList.map((e){
          return YBWorkTaiBaseYiJiModel.fromJson(e);
        }).toList());
        print('--蚁集&律司-$_youXuanList--');
        notifyListeners();
      }
    },fail: (error){
      _easyRefreshController.refreshCompleted();
    });
  }
}

//已获商机
class YBYiJiLvSiBaseYiHuoProvider with ChangeNotifier {

  List<YBWorkTaiBaseYiJiModel> _yiHuoList = List<YBWorkTaiBaseYiJiModel>();

  List<YBWorkTaiBaseYiJiModel> get yiHuoModelList => _yiHuoList;

  RefreshController _easyRefreshController = RefreshController();

  RefreshController get easyRefreshController => _easyRefreshController;

  int _currentPage = 1;

  Future refreshData(String sysCode,String customerQueryType, String feedbackStatus,String orderBy,String orderRule) async {
    _currentPage = 1;
    getYiHuoDataList(_currentPage, sysCode,customerQueryType,feedbackStatus,orderBy,orderRule);
  }

  Future loadData(String sysCode, String customerQueryType, String feedbackStatus,String orderBy,String orderRule) async {
    _currentPage++;
    getYiHuoDataList(_currentPage, sysCode,customerQueryType,feedbackStatus,orderBy,orderRule);
  }

  Future getYiHuoDataList(int page,String sysCode,String customerQueryType, String feedbackStatus,String orderBy,String orderRule) async {
    Map<String,dynamic> statusMap = Map<String,dynamic>();
    /*"sysCode":sysCode,
      "customerQueryType":customerQueryType,
      "feedbackStatus":feedbackStatus,
      "orderBy":orderBy,
      "orderRule":orderRule,
      "pageSize":20,
      "pageNo":page,
    */

    statusMap["sysCode"] = sysCode;
    // if (!ObjectUtil.isEmptyString(feedbackStatus)) {
    //    statusMap['feedbackStatus'] = feedbackStatus;
    // }
    statusMap['pageSize'] = 20;
    statusMap['pageNo'] = page;
    statusMap['orderRule'] = orderRule;
    statusMap['orderBy'] = orderBy;
    statusMap['customerQueryType'] = customerQueryType;

    YBBaseWorkTaiNetWork.workTaiYouXuanShangJi(statusMap,success:(data){
      print("----$data----");

      if (page == 1){
        _yiHuoList.clear();
      }
      _easyRefreshController.loadComplete();
      _easyRefreshController.refreshCompleted();
      int totalPage = data['totalPage'];
      if (totalPage == page) {
        _easyRefreshController.loadNoData();
      }
      List resultList = data['result'];
      if (!ObjectUtil.isEmptyList(resultList)) {
        _yiHuoList.addAll(resultList.map((e){
          return YBWorkTaiBaseYiJiModel.fromJson(e);
        }).toList());
        print('--蚁集&律司-$_yiHuoList--');
        notifyListeners();
      }
    },fail: (error){
      _easyRefreshController.refreshCompleted();
    });
  }
}

//有效商机
class YBYiJiLvSiBaseYouXiaoProvider with ChangeNotifier {

  List<YBWorkTaiBaseYiJiModel> _youXiaoList = List<YBWorkTaiBaseYiJiModel>();

  List<YBWorkTaiBaseYiJiModel> get youXiaoModelList => _youXiaoList;

  RefreshController _easyRefreshController = RefreshController();

  RefreshController get easyRefreshController => _easyRefreshController;

  int _currentPage = 1;

  Future refreshData(String sysCode,String customerQueryType, String status) async {
    _currentPage = 1;
    getYouXiaoDataList(_currentPage, sysCode,customerQueryType,status);
  }

  Future loadData(String sysCode, String customerQueryType, String status) async {
    _currentPage++;
    getYouXiaoDataList(_currentPage, sysCode,customerQueryType,status);
  }

  Future getYouXiaoDataList(int page,String sysCode,String customerQueryType, String status) async {
    YBBaseWorkTaiNetWork.workTaiYiJitongLvSitongYouXiaoShangJi({
      "sysCode":sysCode,
      "customerQueryType":customerQueryType,
      "status":status,
      "pageSize":20,
      "pageNo":page,
    },success:(data){
      print("----$data----");
      _easyRefreshController.loadComplete();
      _easyRefreshController.refreshCompleted();
      int totalPage = data['totalPage'];
      if (totalPage == page) {
        _easyRefreshController.loadNoData();
      }
      List resultList = data['result'];
      if (!ObjectUtil.isEmptyList(resultList)) {
        _youXiaoList.addAll(resultList.map((e){
          return YBWorkTaiBaseYiJiModel.fromJson(e);
        }).toList());
        print('--蚁集&律司-$_youXiaoList--');
        notifyListeners();
      }
    },fail: (error){
      _easyRefreshController.refreshCompleted();
    });
  }
}

//异议商机
class YBYiJiLvSiBaseYiYiProvider with ChangeNotifier {

  List<YBWorkTaiBaseYiJiModel> _yiYiList = List<YBWorkTaiBaseYiJiModel>();

  List<YBWorkTaiBaseYiJiModel> get yiYiModelList => _yiYiList;

  RefreshController _easyRefreshController = RefreshController();

  RefreshController get easyRefreshController => _easyRefreshController;

  int _currentPage = 1;

  Future refreshData(String sysCode,String customerQueryType, String status,String orderBy,String orderRule) async {
    _currentPage = 1;
    getYiYiDataList(_currentPage, sysCode,customerQueryType,status,orderBy,orderRule);
  }

  Future loadData(String sysCode, String customerQueryType, String status,String orderBy,String orderRule) async {
    _currentPage++;
    getYiYiDataList(_currentPage, sysCode,customerQueryType,status,orderBy,orderRule);
  }

  Future getYiYiDataList(int page,String sysCode,String customerQueryType, String status,String orderBy,String orderRule) async {
    YBBaseWorkTaiNetWork.workTaiYiYiShangJi({
      "sysCode":sysCode,
      "customerQueryType":customerQueryType,
      "status":status,
      "orderBy":orderBy,
      "orderRule":orderRule,
      "pageSize":20,
      "pageNo":page,
    },success:(data){
      print("----$data----");
      _easyRefreshController.refreshCompleted();
      _easyRefreshController.loadComplete();
      int totalPage = data['totalPage'];
      if (totalPage == page) {
        _easyRefreshController.loadNoData();
      }
      List resultList = data['result'];
      if (!ObjectUtil.isEmptyList(resultList)) {
        _yiYiList.addAll(resultList.map((e){
          return YBWorkTaiBaseYiJiModel.fromJson(e);
        }).toList());
        print('--蚁集&律司-$_yiYiList--');
        notifyListeners();
      }
    },fail: (error){
      _easyRefreshController.refreshCompleted();
    });
  }
}


//蚁集通&&律司通 公共商机--详情展示页
class YBGongGongYouXuanDetailProvider with ChangeNotifier {

  YBWorkTaiGongGongYouXuanModel gongGongYouXuanModel;

  Future getGongGongYouXuanDataList(String sysCode,String requestCode) async {
    YBBaseWorkTaiNetWork.workTaiGonggongShangJi({
      "sysCode":sysCode,
      "requestCode":requestCode
      },success:(data){
      print("----$data----");
      gongGongYouXuanModel = YBWorkTaiGongGongYouXuanModel.fromJson(data);
      notifyListeners();
    },fail: (error){
      print("---object---$error");
    });
  }
}

//蚁集通&&律司通 公共商机--详情展示页
class YBGongGongYouXuanRealDetailProvider with ChangeNotifier {

  YBWorkTaiGongGongYouXuanModel gongGongYouXuanModel;

  Future getGongGongYouXuanDataList(String sysCode,String requestCode) async {
    YBBaseWorkTaiNetWork.workTaiYouXuanDetailPage({
      "sysCode":sysCode,
      "requestCode":requestCode
    },success:(data){
      print("----$data----");
      gongGongYouXuanModel = YBWorkTaiGongGongYouXuanModel.fromJson(data);
      notifyListeners();
    },fail: (error){
      print("---object---$error");
    });
  }
}

//蚁集通&&律司通 优选商机--详情展示页
class YBYIJiTonglvsiTongYouXuanDetailProvider with ChangeNotifier {

  YBWorkTaiGongGongYouXuanModel gongGongYouXuanModel;

  Future getGongGongYouXuanDataList(String sysCode,String requestCode) async {
    YBBaseWorkTaiNetWork.workTaiYouXuanDetailPage({
      "sysCode":sysCode,
      "requestCode":requestCode
    },success:(data){
      print("----$data----");
      gongGongYouXuanModel = YBWorkTaiGongGongYouXuanModel.fromJson(data);
      notifyListeners();
    },fail: (error){
      print("---object---$error");
    });
  }
}

//蚁集通&&律司通 公共商机--今天剩余次数
class YBGongGongShengYuNumberProvider with ChangeNotifier {

  int todayShengYuNumberStr;

  Future getGongGongYouXuanDataList(String sysCode) async {
    YBBaseWorkTaiNetWork.workTaiGongGongShengYuhaworkTaiGonggongShangJingJi({
      "sysCode":sysCode,
    },success:(data){
      print("----$data----");
      todayShengYuNumberStr = data;
      notifyListeners();
    },fail: (error){
      print("---object---$error");
    });
  }
}

//抢夺商机
class YBGongGongQiangDuoProvider with ChangeNotifier {

  bool todayShengYuNumberStr;

  Future getGongGongYouXuanDataList(String sysCode,String requestCode) async {
    YBBaseWorkTaiNetWork.workTaiGongGongQiangDuoShangJi({
      "sysCode":sysCode,
      "requestCode":requestCode
    },success:(data){
      print("----$data----");
      todayShengYuNumberStr = data;
      if (todayShengYuNumberStr == true){
         EasyLoading.showSuccess('抢夺成功');
         shuaXinShengYuchiShuEventBus.fire(YBShuaXinShengYuChiShuEventBus(shengYuciShu: "1"));
      }
      notifyListeners();
    },fail: (error){
      print("---object---$error");
    });
  }
}




